package tickets.tickets;

import tickets.ticketRegister.TicketRegister;
import tickets.ticketRegister.TicketRegisterImpl;
import tickets.timingService.TimingServiceImpl;
import tickets.timingService.TimingService;
import java.util.Date;
import myutil.mylist.MyList;
import tickets.passageRegister.PassageRegister;
import tickets.passageRegister.PassageRegisterImpl;

/**
 *
 * @author Hlib_Babii
 */
public class Tickets {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws WrongTicketTypeException {
        TimingService timingService = new TimingServiceImpl();
        PassageRegister passageRegister = new PassageRegisterImpl();
        TicketRegister ticketRegister = new TicketRegisterImpl();
        int ticketPrice = 2;
        TicketPurchaseSystem ticketsSys = new TicketPurchaseSystem(ticketRegister, ticketPrice);

        Turnstile turnstile
                = new Turnstile(ticketRegister, passageRegister, timingService);

        Date expDate = new Date(System.currentTimeMillis() + 500000000);
        int nTravels = 2;
        int moneyOnTicket = 3;

        Ticket studTravels = ticketsSys.createStudentLimitedTravelsTicket(nTravels);
        turnstile.applyTicket(studTravels.getId());
        turnstile.applyTicket(studTravels.getId());
        turnstile.applyTicket(studTravels.getId());

        Ticket studDuration = ticketsSys.createStudentLimitedDurationTicket(expDate);
        turnstile.applyTicket(studDuration.getId());
        turnstile.applyTicket(studDuration.getId());
        turnstile.applyTicket(studDuration.getId());

        Ticket schoolTravels = ticketsSys.createSchoolkidsLimitedTravelsTicket(nTravels);
        turnstile.applyTicket(schoolTravels.getId());    
        turnstile.applyTicket(schoolTravels.getId());
        turnstile.applyTicket(schoolTravels.getId());
        
        Ticket schoolDuration = ticketsSys.createSchoolkidsLimitedDurationTicket(expDate);
        turnstile.applyTicket(schoolDuration.getId());   
        turnstile.applyTicket(schoolDuration.getId()); 
        turnstile.applyTicket(schoolDuration.getId()); 
        
        Ticket usualTravels = ticketsSys.createUsualLimitedTravelsTicket(nTravels);
        turnstile.applyTicket(usualTravels.getId()); 
        turnstile.applyTicket(usualTravels.getId());
        turnstile.applyTicket(usualTravels.getId());
        
        Ticket usualDuration = ticketsSys.createUsualLimitedDurationTicket(expDate);
        turnstile.applyTicket(usualDuration.getId());        
        turnstile.applyTicket(usualDuration.getId());
        turnstile.applyTicket(usualDuration.getId());
        
        Ticket usualMoney = ticketsSys.createUsualLimitedMoneyTicket(moneyOnTicket);
        turnstile.applyTicket(usualMoney.getId());
        turnstile.applyTicket(usualMoney.getId());
        turnstile.applyTicket(usualMoney.getId());
        
        turnstile.applyTicket(67);
        
        ticketsSys.putMoney(6, 5);
        turnstile.applyTicket(usualMoney.getId());
        
//        MyList<Passage> passages = passageRegister.getPassages();
//        for (Passage p : passages) {
//            Ticket t = p.getTicket();
//            System.out.println((t != null) ? t.getId() : "?" + " " 
//                    + p.getTime() + " " + p.getPassageState());
//        }
        
        MyList<Passage> passages2 = passageRegister.getPassages(TicketType.USUAL_TICKET);
        for (Passage p : passages2) {
            Ticket t = p.getTicket();
            System.out.println(t.getId() + " " 
                    + p.getTime() + " " + p.getPassageState());
        }
    }
}
